import prompt from '@system.prompt';
import router from '@system.router';

export default {
    data: {
        title: "",
        top: 0,
        opacityNum: 0,
        showOpacity: true,
        dataTime: new Date(),
        lock: false,
        trimmed: null,
        rotateNum: 0,
        message: '',
        dataList: [],
        i: 0,
        count: 0,
        stopTimer: null, //list存放数组的下标，i为下标值，默认从下标为0的开始，也就是左上角的高档洋房一套，count用于判断是否与随机数相等每次加一
        randomn: null,
        residue: 0,
        timer: null,
        time: 0,
    },
    onInit() {

        this.title = this.$t('strings.world');
        this.randomn = Math.floor(Math.random() * 8 + 50) // 创建随机数随机数
        if (!this.data1) this.data1 = 0
    },
    showToast(name) {
        prompt.showToast({
            message: name,
            duration: 4000,
            bottom: 650,
        });
    },
    //点击开始抽奖
    handlerBut() {
        this.timer = new Date()
        if (this.timer - this.time < 8000) return
        this.time = this.timer
        if (this.data1 == 0) {
            this.showToast('剩余次数不足，请充值')
        } else {
            this.data1--
            this.stopTimer = setInterval(this.handlerRevolving, 300)

        }
    },
//    点击查看奖品显示区域
    handlerExamine() {
        if (this.showOpacity) {
            this.opacityNum = .7
            this.showOpacity = false
        } else {
            this.opacityNum = 0
            this.showOpacity = true
        }
    },
//    点击开始抽奖定时器执行函数
    handlerRevolving() {
        this.i++
        if (this.i === 8) {
            this.i = 0
        }
        this.count++
        if (this.count === 5 || this.count === 45) {
            clearInterval(this.stopTimer);
            this.stopTimer = setInterval(this.handlerRevolving, 200);
        }
        if (this.count === 10 || this.count === 35) {
            clearInterval(this.stopTimer);
            this.stopTimer = setInterval(this.handlerRevolving, 100);
        }
        if (this.count === 15) {
            clearInterval(this.stopTimer);
            this.stopTimer = setInterval(this.handlerRevolving, 50);
        }
        // 当等于上面的随机数时，停止计时器
        if (this.count === this.randomn) {
            clearInterval(this.stopTimer);
            this.count = 0 //重置count 的值
            this.randomn = Math.floor(Math.random() * 8 + 50); // 重新获取随机数
            this.dataList.forEach((item, index) => {
                item.top += 30
            })
            switch (this.i) {
                case 0:
                    this.showToast('鸿蒙紫气*1')
                    this.dataList.push({
                        name: '鸿蒙紫气*1',
                        top: this.top
                    })
                    break;
                case 1:
                    this.showToast('现金百万*1')
                    this.dataList.push({
                        name: '现金百万*1',
                        top: this.top
                    })
                    break;
                case 2:
                    this.showToast('复活戒指*1')
                    this.dataList.push({
                        name: '复活戒指*1',
                        top: this.top
                    })
                    break;
                case 3:
                    this.showToast('九阳真经*1')
                    this.dataList.push({
                        name: '九阳真经*1',
                        top: this.top
                    })
                    break;
                case 4:
                    this.showToast('神秘大奖')
                    this.dataList.push({
                        name: '神秘大奖',
                        top: this.top
                    })
                    break;
                case 5:
                    this.showToast('世界树*1')
                    this.dataList.push({
                        name: '世界树*1',
                        top: this.top
                    })
                    break;
                case 6:
                    this.showToast('宇宙战舰*1')
                    this.dataList.push({
                        name: '宇宙战舰*1',
                        top: this.top
                    })
                    break;
                case 7:
                    this.showToast('谢谢参与')
                    this.dataList.push({
                        name: '谢谢参与',
                        top: this.top
                    })
                    break;
            }
        }
    },
    handlerButClear() {
        //        console.log(666)
        router.push({
            uri: 'pages/rechargePage/rechargePage',
            params: {
                data2: this.data1,
            },
        })
    }
}
